// Sample program to show how to write a simple version of curl using
// the io.Reader and io.Writer interface support.
package main

import (
	"io"
	"log"
	"net/http"
	"os"
)

// main is the entry point for the application.
func main() {
	url := os.Args[1]
	// MARK 执行get请求
	r, err := http.Get(url)
	if err != nil {
		log.Fatalln(err)
	}
	content := r.Body //MARK r.Body 是 io.Reader

	fileName := os.Args[2]
	//MARK  创建文件
	file, err := os.Create(fileName)
	if err != nil {
		log.Fatalln(err)
	}
	defer file.Close() //MARK final

	//MARK 合并:标准输出 文件
	dest := io.MultiWriter(os.Stdout, file)
	io.Copy(dest, content) //MARK (目的,来源)

	if err := content.Close(); err != nil {
		log.Println(err)
	}
}
